#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
vector<LL>g[maxn];
LL val[maxn],n,m,s,t;
bool vis[maxn],flag=1;
void predfs(LL u){vis[u]=true;for(LL i=0;i<g[u].size();i++){LL v=g[u][i];if(vis[v]) continue;predfs(v);}}
void dfs1(LL u,LL mid){
    vis[u]=1;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(val[u]>=mid&&val[v]>=mid) flag=0;
        if(vis[v]) continue;
        dfs1(v,mid);
    }
}
void dfs2(LL u,LL mid){
    vis[u]=1;
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i];
        if(vis[v]) continue;
        if( (val[u]>=mid )!=(val[v]>=mid) )dfs2(v,mid);
    }
}
bool check(LL mid){
    memset(vis,0,sizeof(vis));
    flag=1;
    dfs1(s,mid);
    if(0==flag) return true;
    if(val[s]<mid&&val[t]<mid) return false;
    memset(vis,0,sizeof(vis));
    dfs2(s,mid);
    if(vis[t]) return true;
    else return false;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL T;cin>>T;
  while(T--){
    cin>>n>>m>>s>>t;
    for(LL i=1;i<=n;i++) cin>>val[i],g[i].clear(),vis[i]=0;
    for(LL i=1;i<=m;i++){
        LL u,v;cin>>u>>v;
        g[u].push_back(v);g[v].push_back(u);
    }
    predfs(s);
    if(!vis[t]){
        cout<<"NO"<<"\n";
        continue;
    }
    cout<<"YES"<<"\n";
    LL l=1;LL r=1e18;
    while(l<r){
        LL mid=(l+r+1)>>1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l<<"\n";
  }
return 0;
}
